#include "ThreadPool.h"
#include <iostream>
#include <chrono>
#include <atomic>

using namespace std;

int main() {
    ThreadPool pool(2, 4);  // 初始2线程，最大4线程
    atomic<int> counter{0};

    vector<future<void>> results;
    for (int i = 0; i < 10; ++i) {
        results.emplace_back(pool.enqueue([i, &counter] {
            cout << "Task " << i << " started\n";
            this_thread::sleep_for(chrono::seconds(1));
            counter += i;
            cout << "Task " << i << " finished\n";
        }));
    }

    for (auto&& result : results) {
        result.wait();
    }

    cout << "Final counter value: " << counter << endl;
    cout << "Max threads used: " << pool.getThreadCount() << endl;

    return 0;
}